package com.geor.gcv.core.recognizer;

import java.io.IOException;
import java.util.Map;

import org.opencv.core.Mat;
import org.slf4j.Logger;

import com.geor.common.log.Loggers;
import com.geor.gcv.core.mat.Mats;

/**
 * 抽象的处理图片
 * 
 * @author geor.lusongnan
 *
 * @param <A>
 *            <p>
 *            key
 * @param <B>
 *            <p>
 *            value
 */
public abstract class AbstractImageRecognizer<A, B> implements ImageRecognizer<A, B> {
	private Logger log = Loggers.get();

	public AbstractImageRecognizer() {
	}

	@Override
	public Map<A, B> execute(String filepath) {
		Mat mat = null;
		try {
			mat = Mats.imread(filepath);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return execute(mat);
	}

	public Map<A, B> execute(Mat mat) {
		try {
			return _execute(mat);
		} catch (Exception e) {
			log.error("error", e);
		} finally {
			Mats.releseMat(mat);
		}
		return null;
	}

	protected Map<A, B> _execute(Mat mat) {
		return null;
	}

}